Total Complexity | 6 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import React, { Component, Fragment } from "react" |
||
6 | |||
7 | class TeamCalendarMetaMatches extends Component { |
||
8 | constructor(props) { |
||
9 | super(props) |
||
10 | |||
11 | this.state = { |
||
12 | data: [], |
||
13 | loading: true, |
||
14 | } |
||
15 | |||
16 | this.uuid = props.division.toLowerCase() |
||
17 | |||
18 | this.apiServerUrl = props.config.site.siteMetadata.serverUrl |
||
19 | this.apiRefreshRate = props.config.site.siteMetadata.refreshRate |
||
20 | this.timeout = {} |
||
21 | } |
||
22 | |||
23 | updateData() { |
||
24 | const { season, region, division, regnumber } = this.props |
||
25 | |||
26 | fetch( |
||
27 | `${this.apiServerUrl}/meta/${season}/${region}/${division}/${regnumber}` |
||
28 | ) |
||
29 | .then((response) => response.json()) |
||
30 | .then((json) => this.setState({ data: json, loading: false })) |
||
31 | |||
32 | this.timeout = setTimeout(() => { |
||
33 | this.updateData(() => {}) |
||
34 | }, this.apiRefreshRate) |
||
35 | } |
||
36 | |||
37 | componentDidMount() { |
||
38 | this.updateData() |
||
39 | } |
||
40 | |||
41 | componentWillUnmount() { |
||
42 | clearInterval(this.timeout) |
||
43 | } |
||
44 | |||
45 | render() { |
||
46 | if (this.state.loading === false && this.state.data) { |
||
47 | const { next, previous } = this.state.data |
||
48 | |||
49 | if (previous || next) { |
||
50 | return ( |
||
51 | <Fragment> |
||
52 | <div className={"team-calendar-meta-matches"}> |
||
53 | {previous && ( |
||
54 | <MatchWithLogo match={previous.match} lazyload={true} /> |
||
55 | )} |
||
56 | {next && <MatchWithLogo match={next.match} lazyload={true} />} |
||
57 | </div> |
||
58 | </Fragment> |
||
59 | ) |
||
60 | } else { |
||
61 | return null |
||
62 | } |
||
63 | } else { |
||
64 | return null |
||
65 | } |
||
94 |